#pragma once

#include <string>
#include <numeric>

class Decomp
{
public:
	static std::string decompose(const std::string &nrStr, const std::string &drStr);
};

std::string Decomp::decompose( const std::string & nrStr, const std::string & drStr )
{
	uint64_t n = std::stoul(nrStr);
	uint64_t d = std::stoul(drStr);

	std::string res{"["};

	if( n % d == 0 )
		return std::string{"[" + ( n == 0 ? std::string() : std::to_string(n/d) ) + "]"};

	if( n > d ){
		res += std::to_string(n/d);
		n = n % d;
	}
	if( d % n == 0 )
	{
		d /= n;
		n = 1;
	}

	uint64_t h;
	while( n > 1 ){
		h = d/n + 1;
		res += ( res.size() == 1 ? std::string() : std::string(", ") ) + "1/" + std::to_string(h);
		n = n * h - d;
		d *= h;
		if( d % n == 0 ){
			d /= n;
			n = 1;
		}
	}
	res += ( res.size() == 1 ? std::string() : std::string(", ") ) + "1/" + std::to_string(d);

	return res + "]";
}
